/*
 * Micrositio.java
 *
 * Created on 12 de abril de 2007, 12:45
 */

package despachador.administracion;

import excepciones.AvwException;
import gestores.administracion.GestorCampania;
import gestores.administracion.GestorMicrositio;
import java.io.*;
import java.net.*;
import java.util.logging.Logger;

import javax.servlet.*;
import javax.servlet.http.*;
import util.Recurso;
import util.Utiles;

/**
 *
 * @author Administrador
 * @version
 */
public class Campania extends HttpServlet {
    
    static final Logger logger = Utiles.iniciarLogger("Micrositio", true);
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    public void processRequest(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        String camCodigo = "";
        String mswCodigo = "";
        
        if(request.getParameter("opcion")!=null){
            if (request.getParameter("opcion").equals("guardar")){
                camCodigo = String.valueOf(request.getParameter("camCodigo"));
                mswCodigo = String.valueOf(request.getParameter("selectMsw"));
                if (!camCodigo.equals("") && !mswCodigo.equals("")){
                    if (mswCodigo.equals("noAsignar")){
                        GestorCampania.modificarCampania(camCodigo,"");
                    } else{
                        GestorCampania.modificarCampania(camCodigo,mswCodigo);
                    }
                }
                
                response.sendRedirect("index?accion=campania");
            } else{
                armarPagina(request,response);
            }
        } else{
            armarPagina(request,response);
        }
    }
    
    private void armarPagina(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // Especificamos que pagina se coloca en cada parte del layout
        
        request.setAttribute("1", "/vistas/administracion/encabezado.jsp");
        request.setAttribute("2", "/vistas/administracion/menu.jsp");
        request.setAttribute("3", "/vistas/administracion/campania.jsp");
        request.setAttribute("4", "/vistas/administracion/pie.jsp");
        
        dispatch(request, response, "/compositor/administracion/trescuerpos.jsp");
    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
    
    /**
     * dispatcher method
     */
    protected void dispatch(HttpServletRequest request,
            HttpServletResponse response, String page)
            throws javax.servlet.ServletException,
            java.io.IOException {
        RequestDispatcher dispatcher =
                getServletContext().
                getRequestDispatcher(page);
        dispatcher.forward(request, response);
    }
}
